@extends('admin._layout.master')

@section('content')
    <section class="Hui-article-box">
        <nav class="breadcrumb">
            <i class="Hui-iconfont">&#xe67f;</i> 首页
            <span class="c-gray en">&gt;</span> 内容管理
            <span class="c-gray en">&gt;</span> 栏目列表
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
                <i class="Hui-iconfont">&#xe68f;</i>
            </a>
        </nav>
        <div class="pd-20 text-c">
            <div class="cl pd-5 bg-1 bk-gray mt-20">
                <span class="l">共有数据：<strong>{{ $articleTypes->count() }}</strong> 条</span>
            </div>
            <div class="mt-20">
                <table class="table table-border table-bordered table-hover table-bg table-sort">
                    <thead>
                    <tr class="text-c">
                        <th width="80">栏目名</th>
                        <th width="80">栏目类型</th>
                        <th width="80">最后修改时间</th>
                        <th width="100">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($articleTypes as $articleType)
                        <tr class="text-c">
                            <td>{{ $articleType->name }}</td>
                            <td>{{ $articleType->getType($articleType->type) }}</td>
                            <td>{{ $articleType->updated_at }}</td>
                            <td class="f-14">
                                <a title="编辑"
                                   href="{{ route('articleTypeEdit', ['id' => $articleType->id]) }}" style="text-decoration:none">
                                    <i class="Hui-iconfont">&#xe6df;</i>
                                </a>
                                <a title="删除" href="javascript:;"
                                   onclick="article_type_del('{{ $articleType->id }}')"
                                   class="ml-5" style="text-decoration:none;">
                                    <i class="Hui-iconfont">&#xe6e2;</i>
                                </a>
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
        </div>

    </section>
@endsection

@section('javascript')
    <script type="text/javascript" src="{{ asset('lib/My97DatePicker/4.8/WdatePicker.js') }}"></script>
    <script type="text/javascript" src="{{ asset('lib/datatables/1.10.0/jquery.dataTables.min.js') }}"></script>
    <script type="text/javascript" src="{{ asset('lib/laypage/1.2/laypage.js') }}"></script>
    <script type="text/javascript">
        $('.table-sort').dataTable({
            "ordering": false,
            "bStateSave": false,//状态保存
        });

        function article_type_del(id) {
            layer.confirm('确认要删除吗？', function () {
                $.ajax({
                    headers: {'X-CSRF-TOKEN': '{{ csrf_token() }}'},
                    type: 'POST',
                    url: '{{ url('admin/article_type/del') }}',
                    dataType: 'json',
                    data: {id: id},
                    success: function (data) {
                        if (data.code == '0') {
                            location.replace(location.href);
                        } else {
                            layer.msg(data.msg, {icon: 5, time: 3000});
                        }
                    }
                });
            });
        }

        function category_dels(){
            layer.confirm('确认要删除吗？', function() {
                var ids = '';
                $("input[name='ids[]']:checked").each(function () {
                    ids += $(this).val() + ',';
                });
                $.ajax({
                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                    type: 'POST',
                    url: '{{ url('admin/category/dels') }}',
                    dataType: 'json',
                    data: {ids: ids},
                    success: function(data){
                        console.log(data);return;
                        if (data.code == '0') {
                            location.replace(location.href);
                        } else {
                            layer.msg(data.msg, {icon: 5, time: 3000});
                        }
                    }
                });
            });
        }

    </script>
@endsection